import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class DominoManager {
    public static DominoManager Instance = new DominoManager();
    String[] DominoName = {"00","01","02","03","04","05","06","11","12","13","14","15","16","22","23",
            "24","25","26","33","34","35","36","44","45","46","55","56","66"};
    int[] LibraryIndex = new int[28];//打乱的1~28代表牌序
    int NowIndex = 0;
    List<Dominoes> Library = new ArrayList<>();
    public void Init(){
        for(String name: DominoName){
            Library.add(new Dominoes(name));
        }
        Shuffle();
    }
    private void Shuffle(){
        for(int i = 0;i < 28;i++){
            LibraryIndex[i] = i;
        }
        Random r = new Random();
        for(int i = 0;i < LibraryIndex.length;i++) {
            int tmp;
            int x = r.nextInt(LibraryIndex.length);
            tmp = LibraryIndex[i];
            LibraryIndex[i] = LibraryIndex[x];
            LibraryIndex[x] = tmp;
        }
    }
    public Dominoes GetADomino(){
        return Library.get(LibraryIndex[NowIndex++]);
    }
}
